﻿Imports System.Data
Imports System.Data.SqlClient
Public Class DB_Delegate
    Public Table As New DataTable
    Public SQLConnStr As String = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=RenDa;Data Source=localhost"

    Public Function FillDataTable(ByVal selectCommand As String, ByVal tablename As String, Optional ByVal type As String = "select") As String
        '函数说明：若type="select"表示是select语句，还有update、insert
        Dim Table1 As New DataTable(tablename)
        Try

            ' 依据特定的select语句创建一个新的 data adapter。
            Dim dataAdapter As SqlDataAdapter
            dataAdapter = New SqlDataAdapter(selectCommand, SQLConnStr)
            'Select Case type
            'Case "select"
            ' Create a command builder to generate SQL update, insert, and
            ' delete commands based on selectCommand. These are used to
            ' update the database.
            Dim commandBuilder As New SqlCommandBuilder(dataAdapter)

            ' Populate a new data table and bind it to the BindingSource.
            'Dim Table As New DataTable()
            Table.Locale = System.Globalization.CultureInfo.InvariantCulture
            dataAdapter.Fill(Table)

            Return ""
            'Case "update"

            'Case "insert"



            'End Select
            'If type = "select" Then



            'Else

            'End If
            'Me.BindingSource1.DataSource = table
            ' Resize the DataGridView columns to fit the newly loaded content.
            'FormX.DataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader)
        Catch ex As SqlException
            Return "数据库查询失败！请确认数据库运行正常,且所查询时间正确！错误代码：" & ex.ToString()
        End Try

    End Function


End Class
